package diva.pap.model;

import static diva.android_library.lang.AndroidLang.event;
import static diva.lib.lang.Lang.is;

import diva.android_library.lang.AndroidLang;
import diva.android_library.rpc.RequestManager;
import diva.lib.event.Event;
import diva.lib.lang.Base;

public class Application extends Base {

  private static final Application instance = new Application();

  public static Application getInstance() {
    return instance;
  }

  private final Event<Void> eventReload = event();

  private final Settings settings = new Settings();
  private final RequestManager rpc = new RequestManager();
  private String sessionId;

  private Application() {
    AndroidLang.initialize();
  }

  public Event<Void> getEventReload() {
    return eventReload;
  }

  public RequestManager getRpc() {
    return rpc;
  }

  public String getSessionId() {
    return sessionId;
  }

  public Settings getSettings() {
    return settings;
  }

  public boolean isSetup() {
    return is(settings.getServerUrl(), settings.getUsername(), settings.getPassword());
  }

  public void reload() {
    eventReload.run(null);
  }

  public void setSession(String sessionId) {
    this.sessionId = sessionId;
  }
}
